<?php
namespace app\index\controller;
require __DIR__."/../../../qiniu/autoload.php";
use \Qiniu\Auth;

use app\index\model\app as AppModel;

class QiNiu
{
    public function getQiNiuToken()
    {
        //获取七牛云相关信息
        $qiniu = AppModel::get(['id' => 1]);

        $accessKey = $qiniu['qiniuAccessKey'];
        $secretKey = $qiniu['qiniuSecretKey'];
        $bucket = $qiniu['qiniuBucket'];
        // 初始化Auth状态
        $auth = new Auth($accessKey, $secretKey);
        // 简单上传凭证
        $expires = 3600;
        $policy = null;
        $upToken = $auth->uploadToken($bucket);
        
        $json = json_encode([
            "uptoken" => $upToken
        ]);
        return $json;

        

    }
}